import { BroadCastCall } from "../broadCast/BroadCastCall";
import { MessageBlock } from "../../../../Framework/MQ/MessageBlock";
import { SFriendOnlineStatusMsg } from "../../../../Message/Game/SFriendOnlineStatusMsg";
import { Cache } from "../../cache/Cache";
import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { EFriendFlag } from "../../../../Message/Game/EFriendFlag";
import { Language } from "../../../../extend/language/Language";
import { MsgManager } from "../../manager/MsgManager";
//class FriendOnlineStatusCommand
    
    export  class FriendOnlineStatusCommand extends BroadCastCall
    {
        constructor(arg1: Object)
        {
            super(arg1);
            return;
        }

        public /* override */ call(arg1: MessageBlock): void
        {
            super.call(arg1);
            var loc1=arg1.messageBase as SFriendOnlineStatusMsg;
            var loc2=Cache.instance.friend.updateOnlineState(loc1.fromPlayerName, loc1.onlinestatus);
            Cache.instance.friend.updateVIPState(loc1.fromPlayerName, loc1.VIP);
            NetDispatcher.dispatchCmd(ServerCommand.FriendOnlineStatus, loc1);
            if (loc2) 
            {
                this.addTipAndBroadCast(loc1);
            }
            return;
        }

        /* internal  */addTipAndBroadCast(arg1: SFriendOnlineStatusMsg): void
        {
            var loc1=arg1.fromPlayerName;
            var loc2=arg1.onlinestatus;
            var loc3=arg1.flag;
            var loc4="";
            if (loc2) 
            {
                if (loc3 != EFriendFlag._EFriendFlagFriend) 
                {
                    if (loc3 == EFriendFlag._EFriendFlagEnemy) 
                    {
                        loc4 = Language.getStringByParam(90133, loc1);
                    }
                }
                else if (Cache.instance.marry.playerMarry && Cache.instance.marry.playerMarry.mate && Cache.instance.marry.playerMarry.mate.name == loc1) 
                {
                    loc4 = Language.getStringByParam(43500, loc1);
                }
                else 
                {
                    loc4 = Language.getStringByParam(90132, loc1);
                }
            }
            else if (loc3 != EFriendFlag._EFriendFlagFriend) 
            {
                if (loc3 == EFriendFlag._EFriendFlagEnemy) 
                {
                    loc4 = Language.getStringByParam(90135, loc1);
                }
            }
            else if (Cache.instance.marry.playerMarry && Cache.instance.marry.playerMarry.mate && Cache.instance.marry.playerMarry.mate.name == loc1) 
            {
                loc4 = Language.getStringByParam(43501, loc1);
            }
            else 
            {
                loc4 = Language.getStringByParam(90134, loc1);
            }
            if (loc4 != "") 
            {
                MsgManager.addTipText(loc4);
                MsgManager.showRollTipsMsg(loc4);
            }
            return;
        }
    }
